package com.cnfangmao.masterdata.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cnfangmao.masterdata.dao.BasicDataDependationDao;
import com.cnfangmao.masterdata.dto.BasicDataDependationDto;
import com.cnfangmao.masterdata.dto.GeneralSearchDto;
import com.cnfangmao.masterdata.model.BasicDataDependation;
import com.cnfangmao.masterdata.service.BasicDataDependationService;
import com.cnfangmao.masterdata.vo.BasicDataDependationVo;
import com.cnfangmao.masterdata.vo.GeneralPageVo;

/**
 * <p>
 * 主数据间依赖关系表 服务实现类
 * </p>
 *
 * @author chenxd
 * @since 2020-04-14
 */
@Service
public class BasicDataDependationServiceImpl extends ServiceImpl<BasicDataDependationDao, BasicDataDependation> implements BasicDataDependationService {

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.BasicDataDependationService#getBasicDataDependationById(java.lang.String)
	 */
	@Override
	public BasicDataDependationVo getBasicDataDependationById(String dependationId) {
		return this.baseMapper.queryBasicDataDependationById(dependationId);
	}

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.BasicDataDependationService#getBasicDataDependationBySourceId(java.lang.String, java.lang.String)
	 */
	@Override
	public BasicDataDependationVo getBasicDataDependationBySourceId(String sourceMetadataId, String sourceFieldId) {
		return this.baseMapper.queryBasicDataDependationBySourceId(sourceMetadataId, sourceFieldId);
	}

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.BasicDataDependationService#getAllBasicDataDependations()
	 */
	@Override
	public List<BasicDataDependationVo> getAllBasicDataDependations() {
		return this.baseMapper.queryAllBasicDataDependations();
	}

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.BasicDataDependationService#getBasicDataDependationsByPage(com.cnfangmao.masterdata.dto.GeneralSearchDto)
	 */
	@Override
	public GeneralPageVo<BasicDataDependationVo> getBasicDataDependationsByPage(GeneralSearchDto<BasicDataDependationDto> searchDto) {
		IPage<BasicDataDependationVo> page = new Page<BasicDataDependationVo>(searchDto.getPageNo(), searchDto.getPageSize());
		QueryWrapper<BasicDataDependationVo> queryWrapper = new QueryWrapper<BasicDataDependationVo>();
		// queryWrapper.like(!StringUtils.isEmpty(searchDto.getConditions().getSourceMetadataName()), "sbdm.METADATA_NAME", searchDto.getConditions().getSourceMetadataName());
		// queryWrapper.like(!StringUtils.isEmpty(dto.getSourceFieldName()), "sbdfm.FIELD_NAME", dto.getSourceFieldName());
		queryWrapper.orderByDesc("t.MODIFIED_ON");
		
		IPage<BasicDataDependationVo> pageRS = this.baseMapper.queryBasicDataDependationsByPage(page, queryWrapper);
		
		GeneralPageVo<BasicDataDependationVo> pageVo = new GeneralPageVo<BasicDataDependationVo>();
		pageVo.setPageNo(pageRS.getCurrent());
		pageVo.setPageSize(pageRS.getSize());
		pageVo.setTotalCount(pageRS.getTotal());
		pageVo.setRecords(pageRS.getRecords());
		
		return pageVo;
	}
	
}
